import sys, getopt
from Server.DriverServer import urls
from tornado.web import Application
import tornado.ioloop
import multiprocessing


def main(argv):
    port = 8088
    try:
        opts, args = getopt.getopt(argv, "hp:", ["port="])
    except getopt.GetoptError:
        print('AppDriverManager -p <port>')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print('AppDriverManager -p <port>')
            sys.exit()
        elif opt in ("-p", "--port"):
            port = int(arg)
    app = Application(urls, {'debug': True})
    app.listen(port)
    # 创建IOLoop实例并启动
    print('start AppDriverManager success!', flush=True)
    tornado.ioloop.IOLoop.current().start()


if __name__ == "__main__":
    multiprocessing.freeze_support()
    main(sys.argv[1:])
